import 'package:flutter/material.dart';
import 'package:wallpaper_app/pages/images/4k/image_list_new_360.dart';
import 'package:wallpaper_app/pages/images/bocchi/bocchi_page.dart';
import 'package:wallpaper_app/pages/setting/personal_center.dart';
import 'package:wallpaper_app/pages/images/wallhaven/wallhaven_page.dart';
import 'package:wallpaper_app/pages/tools/tools_page.dart';
import 'package:wallpaper_app/tools/custom_image_cache.dart';
import 'package:wallpaper_app/components/SideBar/side_menu_nav.dart';
import 'package:wallpaper_app/components/windows/window_title_bar.dart';
import 'package:wallpaper_app/pages/home_page.dart';
import 'package:wallpaper_app/pages/images/mohu/mohu_page.dart';
import 'package:wallpaper_app/pages/images/suyan/random_image_pc.dart';
import 'package:wallpaper_app/tools/update_apk.dart';

class MainPage extends StatefulWidget {
  const MainPage({super.key});

  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  PageController pageController = PageController();
  void cacheCleaning() async {
    double size = await CustomCacheManager.fileSize();
    // 大于2G 清除缓存
    if (size > 2048) {
      CustomCacheManager.deleteCacheDir();
    }
  }

  @override
  void initState() {
    super.initState();
    cacheCleaning();
    UpdateApk().updateApk(context);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: SizedBox(
      width: double.infinity,
      height: double.infinity,
      child: Row(
        children: [
          // 侧边栏
          // SidebarPage(onTapSide: (index) {
          //   pageController.jumpToPage(index);
          // }),
          SizeMenuNav(onTapSide: (index) {
            pageController.jumpToPage(index);
          }),
          Expanded(
              child: Column(
            children: [
              WindowTitleBar(),
              Expanded(
                child: PageView(
                  controller: pageController,
                  children: [
                    HomePage(),
                    ImageListNew360(),
                    BocchiPage(),
                    WallhavenPage(),
                    RandomImagePc(),
                    MohuPage(),
                    PersonalCenter(),
                    ToolsPage(),
                  ],
                ),
              )
            ],
          ))
        ],
      ),
    ));
  }
}
